<template>
  <div class="bw-node-attr-value">
    <template v-if="valueFrom === BwIfFromTypeEnum.constValue">
      <component
        :is="curConstEle"
        v-bind="curConstEleBindProps"
        v-on="curConstEleEmits"
      />
    </template>

    <template v-else-if="valueFrom === BwIfFromTypeEnum.comVar">
      <a-input
        class="input"
        v-model:value="curComVarName"
        @change="onChangeSeniosValue(curComVarName)"
      />
    </template>

    <template v-else-if="valueFrom === BwIfFromTypeEnum.comProps">
      <a-select
        class="input"
        style="width: 100%"
        :options="curCurtomComPropList"
        v-model:value="curComParamName"
        @change="onChangeSeniosValue(curComParamName)"
      />
    </template>

    <template v-else-if="valueFrom === BwIfFromTypeEnum.JSExpression">
      <a-button :block="true" type="primary" @click="curVisible = true">
        表达式定义
      </a-button>
    </template>

    <BwJSExtend
      v-model:visible="curVisible"
      :value="curJSExpression"
      @ok="onChangeJSExpression"
    />
  </div>
</template>

<script lang="ts" setup>
import { useSeniorValue } from './util'

import BwJSExtend from '../../../../../coms/JSExtend/index.vue'

import {
  BwCustomComNodeIfFromTypeEnum as BwIfFromTypeEnum,
  BwCustomComNodeForFromTypeEnum as BwForFromTypeEnum,
  BwCustomComNodeAttrDataTypeEnum as BwAttrDataTypeEnum,
  type BwCustomComNodeIfInfoModel,
  type BwCustomComNodeForInfoModel,
} from '@bitwit/base-com-render'
interface BwSeniorValueProps {
  valueDataType: BwAttrDataTypeEnum
  valueFrom: BwIfFromTypeEnum | BwForFromTypeEnum
  info: BwCustomComNodeIfInfoModel | BwCustomComNodeForInfoModel
}

const emit = defineEmits(['change'])
const props = withDefaults(defineProps<BwSeniorValueProps>(), {
  valueFrom: BwIfFromTypeEnum.constValue,
  valueDataType: BwAttrDataTypeEnum.string,
})

const {
  curVisible,
  curConstEle,
  curComVarName,
  curComParamName,
  curJSExpression,
  curConstEleEmits,
  curConstEleBindProps,
  curCurtomComPropList,

  onChangeSeniosValue,
  onChangeJSExpression,
} = useSeniorValue(props, emit)
</script>

<style lang="less" scoped></style>
